<template>
  <div>
    <el-dialog
      :title="title"
      :visible.sync="visible"
      width="800px"
      append-to-body
      custom-class="import-dialog"
      @close="close"
    >
      <div class="form-box" v-loading="loading">
        <el-descriptions title="" :column="2">
          <el-descriptions-item label="订单号">{{
            form.orderId
          }}</el-descriptions-item
          ><el-descriptions-item label="状态"
            ><dict-tag
              :options="dict.type.order_short_state"
              :value="form.orderState" /></el-descriptions-item
          ><el-descriptions-item label="当前房间">{{
            form.premisesAddress
          }}</el-descriptions-item
          ><el-descriptions-item label="来源">
            <dict-tag
              :options="dict.type.order_source"
              :value="form.orderSource" /></el-descriptions-item
          ><el-descriptions-item label="入离"
            >{{ form.checkInTime | formatDate("MM-DD") }}至{{
              form.checkOutTime | formatDate("MM-DD")
            }}</el-descriptions-item
          >
          <el-descriptions-item label="入住天数">
            {{diffDays(form.checkInTime, form.checkOutTime)}}
          </el-descriptions-item
          ><el-descriptions-item label="房费">{{
            form.totalRent
          }}</el-descriptions-item
          >
          <el-descriptions-item :label-style="{color: '#EC011C'}" :content-style="{color: '#EC011C'}" label="优惠金额" v-if="form.couponPrice">{{
              form.couponPrice
            }}</el-descriptions-item
          >
          <el-descriptions-item label="押金">{{
              form.deposit
            }}</el-descriptions-item
          >
          <el-descriptions-item label="住客姓名">{{
            form.orderLessee.lesseeName
          }}</el-descriptions-item
          ><el-descriptions-item label="住客手机">{{
            form.orderLessee.phone
          }}</el-descriptions-item>
          <el-descriptions-item label="身份证号">{{
            form.orderLessee.cardNumber
          }}</el-descriptions-item>
        </el-descriptions>
        <el-descriptions title="退订规则" :column="2">
          <el-descriptions-item label="名称">{{
            form.unsubscribeRule.unsubscribeRuleName
          }}</el-descriptions-item>
          <el-descriptions-item label="备注">{{
            form.unsubscribeRule.unsubscribeRemark
          }}</el-descriptions-item
          ><el-descriptions-item label="规则">{{
            form.unsubscribeRule.unsubscribeType == 1 ? "严格模式" : "酒店模式"
          }}</el-descriptions-item>
        </el-descriptions>
        <template v-if="form.unsubscribeRule.unsubscribeType == 1">
          <div>预订成功后30分钟内：全额退款</div>
          <div>入住前1天12:00前：全额退款</div>
          <div>入住前1天12:00后：扣除全部房费</div>
        </template>
        <template v-else>
          <div>预订成功后30分钟内：全额退款</div>
          <div>入住当天00:00前：全额退款</div>
          <div>
            入住当天12:00前：按房费比例扣除，扣除首晚房费{{
              unsubscribeContentMap.a
            }}%
          </div>
          <div>
            入住当天18:00前：按房费比例扣除，扣除首晚房费{{
              unsubscribeContentMap.b
            }}%
          </div>
          <div>
            入住当天18:00后或已入住：当天不可取消，未入住日期按比例扣除，扣除当天房费{{
              unsubscribeContentMap.c
            }}%
          </div>
        </template>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import formRule from "@/utils/formRule.js";
import { orderInfo } from "@/api/order/short";
import { diffDays } from '@/utils/common/moment'
export default {
  name: "signOrder",
  dicts: ["order_short_state", "order_source"],
  components: {},
  props: {
    title: {
      default: "详情",
    },
    value: {
      default: false,
    },
    orderId: {
      default: undefined,
    },
    isDetail: {
      default: false,
    },
    success: {
      type: Function,
      default: () => {},
    },
  },
  data() {
    return {
      loading: false,
      unsubscribeContentMap: {},
      dialogSelectHouseVisible: false,
      form: {
        orderLessee: {
        },
        unsubscribeRule: {
        },
      },
    };
  },
  computed: {
    visible:{
      get(){
        return this.value;
      },
      set(val){
        this.$emit("input", val);
      }
    }
  },
  watch: {
    value:{
      handler(val){
        if(val){
          this.init();
        }
      },
      immediate: true
    }
  },
  methods: {
    diffDays,
    init() {
      this.getInfo();
    },
    //获取详情
    getInfo() {
      if (!this.orderId) return;
      this.loading = true;
      orderInfo(this.orderId).then((response) => {
        this.form = response.data;
        let unsubscribeContentMap={};
        console.log(this.form.unsubscribeRule.unsubscribeContentMap[1])
        if (this.form.unsubscribeRule.unsubscribeContentMap) {
          unsubscribeContentMap['a'] =
            this.form.unsubscribeRule.unsubscribeContentMap[1];
          unsubscribeContentMap['b'] =
            this.form.unsubscribeRule.unsubscribeContentMap[2];
          unsubscribeContentMap['c'] =
            this.form.unsubscribeRule.unsubscribeContentMap[3];
          this.unsubscribeContentMap = unsubscribeContentMap;
        }
        this.loading = false;
      }).catch((error) => {
        this.loading = false;
      });
    },
    //关闭
    close() {
      this.$emit("input", false);
    },
  },
};
</script>

<style lang="scss" scoped>
.import-dialog {
  height: auto;
  max-height: 80vh;
  overflow-y: auto;
  .dialog-footer {
    text-align: center;
  }
}
::v-deep .el-dialog__body {
  max-height: 80vh !important;
  overflow-y: auto;
}
.form-box {
  .tabs {
    display: flex;
    .tabs-item {
      padding: 0 10px;
      height: 40px;
      line-height: 40px;
      font-size: 16px;
      position: relative;
      cursor: pointer;
      &::before {
        content: "";
        position: absolute;
        left: 50%;
        bottom: -2px;
        width: 0;
        height: 2px;
        opacity: 0;
        background: #0caaf0;
        transition: all 0.3s;
      }
      &.active {
        color: #0caaf0;
        &::before {
          opacity: 1;
          left: 0;
          width: 100%;
        }
        cursor: default;
      }
    }
  }
  .add-form {
    .section {
      .label {
        display: flex;
        margin-bottom: 20px;
        font-size: 16px;
        align-items: center;
        color: #303133;
        label {
          display: block;
          width: 80px;
          &.dot::before {
            content: "*";
            color: #ff4949;
            margin-right: 4px;
          }
        }
        .icon {
          color: #02a7f0;
          font-size: 30px;
          margin-left: 30px;
          cursor: pointer;
        }
      }
      .tips {
        color: #aaaaaa;
      }
      .custom-formItem-lable {
        display: flex;
        align-items: center;
        .handle-icon {
          color: #02a7f0;
          font-size: 30px;
          margin-left: 30px;
          cursor: pointer;
        }
      }
      .handle-icon {
        color: #02a7f0;
        font-size: 30px;
        cursor: pointer;
      }
    }
  }
}
</style>
